#ifndef USER_TASK_H
#define USER_TASK_H

#ifdef __cplusplus
extern "C" {
#endif

#include <cmsis_os2.h>
#include "FreeRTOS.h"
#include "task.h"

#include "TopDefine.h"
/* Exported constants ------------------------------------------------------- */

/* 所有任务都要define一个“任务运行频率”和“初始化延时” */
#define TASK_FREQ_CTRL_GIMBAL (250u)
#define TASK_FREQ_CTRL_SHOOT (500u)
#define TASK_FREQ_CTRL_COMMAND (500u)
#define TASK_FREQ_MONITOR (2u)
#define TASK_FREQ_CAN (1500u)
#define TASK_FREQ_AI (500u)
#define TASK_FREQ_BALL (500u)

#define TASK_INIT_DELAY_INFO (500u)
#define TASK_INIT_DELAY_MONITOR (10)
#define TASK_INIT_DELAY_REFEREE (400u)
#define TASK_INIT_DELAY_AI (400u)


/* Exported defines --------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */



typedef struct
{
    /*线程任务*/
    struct
    {
        osThreadId_t can;
        //osThreadId_t rc;
        osThreadId_t nuc;
        osThreadId_t shoot;
        osThreadId_t gimbal;
        //osThreadId_t handling;
        osThreadId_t ball;
        osThreadId_t dm;

    }thread;
    
    /*消息队列*/
    struct
    {
        osMessageQueueId_t msg; 
        osMessageQueueId_t nuc;
        osMessageQueueId_t status;
    }msgq;
    /*事件组*/
    struct
    {
        osEventFlagsId_t eventReceive;
    }events;

    #ifdef DEBUG
    struct {
        UBaseType_t can;
        //UBaseType_t rc;
        UBaseType_t nuc;
        UBaseType_t shoot;
        UBaseType_t gimbal;
        //UBaseType_t handling;
        UBaseType_t ball;
        UBaseType_t dm;

    } stack_water_mark; /* stack使用 */

    struct {
        float can;
        //float rc;
        float nuc;
        float shoot;
        float gimbal;
        //float handling;
        float ball;

    } freq; /* 任务运行频率 */

    struct {
        float can;
        //float rc;
        float nuc;
        float shoot;
        float gimbal;
        //float handling;
        float ball;
    } last_up_time; /* 任务最近运行时 */
#endif

}task_t;

/* Exported functions ------------------------------------------------------- */
extern task_t task_struct; /* 任务结构体实例化 */
extern const osThreadAttr_t attr_shoot;
extern const osThreadAttr_t attr_gimbal;
extern const osThreadAttr_t attr_can;
extern const osThreadAttr_t attr_ball;
extern const osThreadAttr_t attr_nuc;
extern const osThreadAttr_t attr_dm;
extern const osEventFlagsAttr_t attr_event;


/* Exported functions prototypes -------------------------------------------- */
void FunctionTake(void *argument);
void FunctionGimbal(void *argument);
void FunctionShoot(void *argument);
void FunctionCan(void *argument);
void FunctionRc(void *argument);
void FunctionBall(void *argument);
void Function_nuc(void *argument);
void Function_DM(void *argument);

#ifdef __cplusplus
}
#endif

#endif
